package com.example.service;

import com.example.entity.Account;
import com.example.entity.LevelThree;
import com.example.mapper.LevelThreeMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 三级机构
 **/
@Service
public class LevelThreeService {

    @Resource
    private LevelThreeMapper levelthreeMapper;

    /**
     * 新增
     */
    public void add(LevelThree levelthree) {
        Account currentUser = TokenUtils.getCurrentUser();
       levelthreeMapper.insert(levelthree);
    }
    /**
     * 新增
     */
    public LevelThree addAndGet(LevelThree levelthree) {
//        Account currentUser = TokenUtils.getCurrentUser();
        levelthreeMapper.insert(levelthree);
        // 假设id是自动生成的，需要重新查询插入的数据以获取生成的id
        return levelthreeMapper.selectById(levelthree.getId());
    }
    /**
     * 删除
     */
    public void deleteById(Integer id) {
       levelthreeMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
           levelthreeMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(LevelThree levelthree) {
       levelthreeMapper.updateById(levelthree);
    }

    /**
     * 根据ID查询
     */
    public LevelThree selectById(Integer id) {
        return levelthreeMapper.selectById(id);
    }
    /**
     * 查询所有
     */
    public List<LevelThree> selectAll(LevelThree levelthree) {
        return levelthreeMapper.selectAll(levelthree);
    }

    /**
     * 分页查询
     */
    public PageInfo<LevelThree> selectPage(LevelThree levelthree, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<LevelThree> list =levelthreeMapper.selectAll(levelthree);
        return PageInfo.of(list);
    }

}